<template>
	<view class="container" >
			<!-- <uni-section type="line" padding>
				<view class="example-body">
					<view v-for="item in titleLists" @click="clickItem(item.id)"
					:class="{'tag-view': true,'active': item.checked}">
						{{item.text}}
					</view>
				</view>
			</uni-section> -->
			<view class="goods-list">
				<view class="item"  v-for="(item, index) in goodsData">
					<goods-number ref="goodsNumber" :itemList="item" goodsType="deliver"  @getLists="getDatas"></goods-number>
				</view>
				<uni-load-more :status="pageParams.isMore" />
			</view>
	</view>
</template>

<script>
import { getDeliverGoodsData } from "@/api/system/goods.js"
import { getTenantId,getDriverId,getOpenId } from '@/utils/auth';

export default {
	data() {
		return {
			goodsData:[],
			dataLists:[],
			queryParam: {
			    driverId: undefined,// uni.getStorageSync('sjxxData').id,
			    enterId: undefined,
				currentPage:1,
				pageSize:10
			},
			pageParams: {
				isMore: 'more'
			},
			titleLists:[
				{
					id:1,
					text:'待审核',
					checked: true,
				},
				{
					id:2,
					text:'进行中',
					checked: false,
				},
				{
					id:3,
					text:'已完成',
					checked: false,
				}
			]
		}
	},
	methods: {
		onReachBottom() {
			if (this.pageParams.isMore == 'more') {
				this.queryParam.currentPage++;
				this.getDatas();
			}
		},
		async getDatas(){
			this.queryParam.driverId = getDriverId()
			this.queryParam.enterId = getTenantId()
			this.pageParams.isMore = 'loading';
			let res = await getDeliverGoodsData(this.queryParam)
			console.log(res,'司机的信息')
			if(res.code == "200"){
				if(this.queryParam.currentPage == 1){
					this.goodsData = res.data.rows;
				}else{
					this.goodsData = [...this.goodsData, ...res.data.rows];
				}
				if (res.data.total == this.goodsData.length) {
					this.pageParams.isMore = 'noMore';
				} else {
					this.pageParams.isMore = 'more';
				}
			}else{
				this.goodsData = []
				this.pageParams.isMore = 'noMore'
			}
			//停止下拉刷新
			wx.hideNavigationBarLoading();
			//停止下拉刷新
			wx.stopPullDownRefresh();
		},
		clickItem(id){
			this.titleLists.forEach(item=>{
				item.checked = false
				if(item.id == id) item.checked = true
			})
			this.goodsData = this.dataLists.filter(item=>{
				if(id == 1){
					return item.queueStatus == 40000
				}else if(id == 2){
					return item.queueStatus < 90000 && item.queueStatus > 40000
				}else{
					return item.queueStatus == 90000
				}
			})
		}
	},
	onLoad() {
		this.getDatas()
		console.log(this.goodsData,'这是货物列表')
	},
	onPullDownRefresh() {
		this.queryParam.currentPage = 1
		this.getDatas()
	},
	onShow(){
    this.$nextTick(() => {
      if (Array.isArray(this.$refs.goodsNumber)) {
        this.$refs.goodsNumber.forEach(ref => {
          if (ref && typeof ref.closePopupReupload === 'function') {
            ref.closePopupReupload();
          }
        });
      }
    })
    this.queryParam.currentPage = 1
    this.getDatas()
  }
};
</script>

<style lang="scss" scoped>
	.container{
		.goods-list{
			padding: 20rpx;
			.item{
				margin-bottom: 20rpx;
			}
		}
		.multi-box{
			border: 1px solid #ccc;
			border-radius: 3px;
			height: 30px;
			line-height: 30px;
			padding: 0 3px;
		}
	}
</style>
